home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / thread / initializeTcb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  7.3 KB  |  280 lines

  1. /*
  2.  *   $RCSfile: initializeTcb.c,v $  
  3.  *   $Revision: 1.2 $  
  4.  *   $Date: 1996/05/04 23:51:54 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38. #include "sysdefs.h"
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "trace.h"
  42. #include "error.h"
  43. #include "list.h"
  44. #include "tid.h"
  45. #include "io.h"
  46. #include "lock.h"
  47. #include "object.h"
  48. #include "msgdefs.h"
  49. #include "thread.h"
  50. #include "thread_funcs.h"
  51. #include "queue_globals.h"
  52. #include "threadstate.h"
  53. #include "thread_globals.h"
  54. #include "queue_consist.h"
  55. #include "ips_support.h"
  56.  
  57. #ifdef DEBUG
  58.  void
  59. dumpTcb(
  60.     register TCB    *tcb
  61. )
  62. {
  63.     static char *states[]={
  64.     "INACTIVE",    /* -2 */
  65.     "LOOP",
  66.     "ACTIVE",    /* 0 */
  67.     "SEMAPHORE_WAIT",
  68.     "SH_LATCH_WAIT",
  69.     "EX_LATCH_WAIT",
  70.     "SPARE_TCB",
  71.     "DISK_WAIT",
  72.     "RECEIVE_WAIT",
  73.     "DISKOPEN_WAIT",
  74.     "DISKCLOSE_WAIT",     /* 8 */
  75.     "LOCK_WAIT",
  76.     "LOCKUPGRADE_WAIT",
  77.     "LOG_QUIESCE_WAIT",    /* 11 */
  78.     "TRANS_QUIESCE_WAIT",
  79.     "LOG_RECOVERY_WAIT",
  80.     "BUFGROUP_WAIT",
  81.     "CHECKPOINT_WAIT", /* 15 */
  82.     "DISKFORMAT_WAIT",
  83.     "LOG_CLOSE_WAIT",
  84.     "DISK_Q_WAIT",/* 18 */
  85.     "TRANS_SHUTDOWN_WAIT",
  86.     "LOG_PREFLUSH_WAIT", /* 20 */
  87.     "THREAD_READY_WAIT", /* 21 */
  88.     "THREAD_RECOVER_UNDO_WAIT",
  89.     "THREAD_WAKEUP_WAIT",
  90.     "THREAD_TIMER_IN_USE",    /* 24 */
  91.     "DIRTY_PAGE_FLUSH_WAIT", /* 25 */
  92.     "THREAD_FORK_WAIT", /* 26 */
  93.     "THREAD_COORD_WAIT" /* 27 */
  94.     };
  95.  
  96.     fprintf(stderr, "THREAD %d state %d/%s\n", 
  97.         tcb->id, tcb->state, 
  98.         (tcb->state > MAX_THREADSTATE)?"UNKNOWN STATE": states[tcb->state+2]);
  99.     fprintf(stderr, 
  100.         "\t[stk 0x%x, sp 0x%x, size %d\n",
  101.         tcb->stack, tcb->sp, (int)(tcb->sp - tcb->stack));
  102.     fprintf(stderr, 
  103.         "\tlists: ctl 0x%x, trans 0x%x\n", tcb->controlList, tcb->transList);
  104.     fprintf(stderr, 
  105.         "\tdiskMsg 0x%x, iovec=[0x%x,%d]\n", tcb->diskMessage,
  106.             tcb->iovec[0].iov_base, tcb->iovec[0].iov_len);
  107.     fprintf(stderr, 
  108.         "\tinitBuf [sp 0x%x, pc 0x%x] \tcurrentBuf [sp 0x%x, pc 0x%x]\n",
  109. #ifdef mips
  110.         tcb->initBuf[JB_SP], tcb->initBuf[JB_PC],
  111.         tcb->currentBuf[JB_SP], tcb->currentBuf[JB_PC]
  112. #elif defined(sparc)
  113.         tcb->initBuf[JB_SP_SPARC], tcb->initBuf[JB_PC_SPARC],
  114.         tcb->currentBuf[JB_SP_SPARC], tcb->currentBuf[JB_PC_SPARC]
  115. #elif defined(linux)
  116.         LINUX_JB_SP(tcb->initBuf), LINUX_JB_PC(tcb->initBuf),
  117.         LINUX_JB_SP(tcb->currentBuf), LINUX_JB_PC(tcb->currentBuf)
  118. #elif defined(_IBMR2)
  119.         tcb->initBuf[JB_SP_AIX], tcb->initBuf[JB_PC_AIX],
  120.         tcb->currentBuf[JB_SP_AIX], tcb->currentBuf[JB_PC_AIX]
  121. #elif defined(hpux)
  122.         HPPA_JB_SP(tcb->initBuf), HPPA_JB_PC(tcb->initBuf),
  123.         HPPA_JB_SP(tcb->currentBuf), HPPA_JB_PC(tcb->currentBuf)
  124. #elif !(defined(mips) || defined(sparc) || defined(_IBMR2) || defined(hpux) || defined(linux))
  125.     not supported
  126. #else
  127.     /* this else should have the not supported code, but the
  128.        ultrix cpp is broken */
  129. #endif
  130.     );
  131.  
  132. } /* dumpTcb */
  133.  
  134.  void
  135. dumpActive()
  136. {
  137.     extern TCB    *Active;
  138.     dumpTcb(Active);
  139. } /* dumpActive */
  140.  
  141. void
  142. dumpTcbs()
  143. {
  144.     register int    i;
  145.  
  146.     for (i = 0; i < NumThreads; i++) {
  147.         dumpTcb(&Tcbs[i]);
  148.     }
  149.     dumpActive();
  150. }
  151. #endif DEBUG
  152.  
  153. void
  154. reinitTcb(TCB *tcb) 
  155. {
  156.     tcb->state = THREAD_INACTIVE;
  157.  
  158.     tcb->transRec = NULL;
  159.     tcb->semCount = 0;    /* no semaphores held */
  160.     tcb->replyAddr.sin_family = AF_INET;
  161.     tcb->replyAddr.sin_addr.s_addr = INADDR_ANY;
  162.     tcb->error = tcb->errno = esmNOERROR;
  163. }
  164.  
  165.  void
  166. initializeTcb (
  167.  
  168.     register PFI    pc,
  169.     register TCB    *tcb,
  170.     register FOUR    *stack,
  171.     register FOUR    stackSize  /* not used */
  172.  
  173. )
  174. {
  175.  
  176. #ifdef _IBMR2
  177.     FCN_DESC  *fcn_desc;
  178. #endif
  179.  
  180.     register TCB    *locTcb;
  181.  
  182.  
  183.     TRACE(TR_THREAD, TR_LEVEL_1);
  184.  
  185.     /*
  186.      *    stack grows down so move the pointer there
  187.      */
  188.     /*stack = &stack[stackSize - 1];*/
  189.  
  190.     /*
  191.      *    align the stack pointer
  192.      */
  193.     stack = (long *) (((long) stack) & ~0x7);
  194.     TRPRINT(TR_THREAD, TR_LEVEL_2, ("stack:%x", stack));
  195.     locTcb = tcb;
  196.  
  197.     /*
  198.      *    setup the tcb
  199.      */
  200. #ifdef hpux
  201.     tcb->sp = (long *) &stack[+6];
  202.     stack[5] = FRAMEMARK;
  203.     stack[4] = FRAMEMARK;
  204.     stack[3] = FRAMEMARK;
  205.     stack[2] = FRAMEMARK;
  206.     stack[1] = FRAMEMARK;
  207.     stack[0] = FRAMEMARK;
  208. #elif defined(sparc) || defined(mips) || defined(_AIX) || defined(linux)
  209.     tcb->sp = (long *) &stack[-6];
  210.     stack[-5] = FRAMEMARK;
  211.     stack[-4] = FRAMEMARK;
  212.     stack[-3] = FRAMEMARK;
  213.     stack[-2] = FRAMEMARK;
  214.     stack[-1] = FRAMEMARK;
  215.     stack[ 0] = FRAMEMARK;
  216. #else
  217. not supported
  218. #endif
  219.     tcb->stack = stack;
  220.     initializeListElement( &(tcb->controlList), (char *) tcb );
  221.     initializeListElement( &(tcb->transList), (char *) tcb );
  222.  
  223.     tcb->diskMessage = (DISKMSG *) &DiskMessages[tcb->id];
  224.     tcb->diskMessage->body.threadId = tcb->id;
  225.     tcb->iovec[0].iov_base = (char *) &(tcb->message);
  226.     tcb->iovec[0].iov_len = sizeof(MESSAGE);
  227.     INIT_TCB_MAGIC(tcb);
  228. #ifdef IPS_SUPPORT
  229.     tcb->ipsid = IPSnewThread(NULL);
  230. #endif IPS_SUPPORT
  231.  
  232.  
  233.     /*
  234.      *    save this place
  235.      */
  236.     setjmp(tcb->initBuf);
  237.     setjmp(tcb->currentBuf);
  238.  
  239.     reinitTcb(tcb);
  240.  
  241.  
  242. #ifdef mips
  243.     tcb->initBuf[JB_SP] = (int) tcb->sp;
  244.     tcb->initBuf[JB_PC] = (int) pc;
  245.     tcb->currentBuf[JB_SP] = (int) tcb->sp;
  246.     tcb->currentBuf[JB_PC] = (int) pc;
  247. #elif defined(linux)
  248.     LINUX_JB_PC(tcb->initBuf) = (int) pc;
  249.     LINUX_JB_SP(tcb->initBuf) = (int) tcb->sp;
  250.     LINUX_JB_PC(tcb->currentBuf) = (int) pc;
  251.     LINUX_JB_SP(tcb->currentBuf) = (int) tcb->sp;
  252. #elif defined(sparc)
  253.     tcb->initBuf[JB_SP_SPARC] = (int) tcb->sp;
  254.     tcb->initBuf[JB_PC_SPARC] = (int) pc;
  255.         /*
  256.          *  NPC is set to 4 from the pc
  257.          */
  258.     tcb->initBuf[JB_NPC_SPARC] = ((int) pc) + sizeof(int);
  259.     tcb->currentBuf[JB_SP_SPARC] = (int) tcb->sp;
  260.     tcb->currentBuf[JB_PC_SPARC] = (int) pc;
  261.     tcb->currentBuf[JB_NPC_SPARC] = ((int) pc) + sizeof(int); 
  262. #elif defined(_IBMR2)
  263.     fcn_desc = (FCN_DESC *) pc;
  264.     tcb->initBuf[JB_SP_AIX] = (int) tcb->sp;
  265.     tcb->initBuf[JB_PC_AIX] = (int) fcn_desc->address;
  266.     tcb->currentBuf[JB_SP_AIX] = (int) tcb->sp;
  267.     tcb->currentBuf[JB_PC_AIX] = (int) fcn_desc->address;
  268. #elif defined(hpux)
  269.     HPPA_JB_PC(tcb->initBuf) = (int) pc;
  270.     HPPA_JB_SP(tcb->initBuf) = (int) tcb->sp;
  271.     HPPA_JB_PC(tcb->currentBuf) = (int) pc;
  272.     HPPA_JB_SP(tcb->currentBuf) = (int) tcb->sp;
  273. #elif !(defined(mips) || defined(sparc) || defined(_IBMR2) || defined(hpux) || defined(linux))
  274.     not supported
  275. #else
  276.     /* this else should have the not supported code, but the
  277.        ultrix cpp is broken */
  278. #endif
  279. }
  280.